﻿namespace NTLib.Core.UTest.Extensions
{
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using NTLib.Core.Extensions;

    [TestClass]
    public class ObjectExtensionUTest
    {
        #region Fields

        private const string CATEGORY = "Extensions";

        #endregion

        #region Class

        class A
        {
            public int Prop1 { get; }

            public string Prop2 { get; set; }

            public DateTime Prop3 { get; set; }

            public DateTime Prop5 { get; set; }

            public string UniquePropA { get; set; }

            public A(int value)
            {
                Prop1 = value;
            }
        }

        class B
        {
            public int Prop1 { get; set; }

            public string Prop2 { get; set; }

            public DateTime Prop3 { get; }

            public DateTime Prop4 { get; set; }

            public DateTime Prop5 { get; set; }

            public string UniquePropB { get; set; }

            public B(DateTime time)
            {
                Prop3 = time;
            }
        }

        #endregion

        #region Methods

        [TestCategory(CATEGORY)]
        [TestMethod]
        public void EXT_ObjectCopy()
        {
            string testValue = "TEST";
            int intValue = 42;
            DateTime timeValue = DateTime.Now;

            A objA = new A(intValue);

            objA.Prop2 = testValue;
            objA.Prop3 = timeValue;
            objA.Prop5 = timeValue;
            objA.UniquePropA = testValue;

            B objB = new B(timeValue);

            objA.CopyPropertyValuesTo(objB);

            Assert.AreEqual(objA.Prop2, objB.Prop2);
            Assert.AreEqual(objA.Prop2, testValue);

            Assert.AreEqual(objA.Prop5, objB.Prop5);
            Assert.AreEqual(objA.Prop5, timeValue);

            Assert.AreNotEqual(objA.Prop1, objB.Prop1);
            Assert.AreNotEqual(objA.Prop3, objB.Prop1);
            Assert.AreEqual(objB.Prop4, default(DateTime));
        }

        #endregion
    }
}
